export default {
  // 开启命名空间
  namespaced: true,

  // state 数据
  state: () => ({
    // 收货地址
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    token:uni.getStorageSync('token') || '',
    userinfo:JSON.parse(uni.getStorageSync('userinfo') || '{}'),
    jumpInfo:null
  }),
  // 方法
  mutations: {
    // 更新收货地址
    updateAddress(state, address) {
      state.address = address
      this.commit('m_user/saveAddressStorage')
    },
    saveAddressStorage(state) {
      uni.setStorageSync('address', JSON.stringify(state.address))
    }, 
    // 更新用户信息
    updateUserInfo(state, userinfo) {
      state.userinfo = userinfo
      this.commit('m_user/saveUserInfoStorage')
    },
    saveUserInfoStorage(state) {
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },
    // 更新TOKEN
    updateToken(state, token) {
      state.token = token
      this.commit('m_user/saveTokenStorage')
    },
    saveTokenStorage(state) {
      uni.setStorageSync('token', JSON.stringify(state.token))
    },
     // 更新跳回页面的信息
     updateJumpInfo(state,info){
       state.jumpInfo=info
     }
  },

  // 数据包装器
  getters: {
    addstr(state) {
      const { provinceName, cityName, countyName, detailInfo } = state.address;
      if (provinceName) {
        return provinceName + cityName + countyName + detailInfo;
      } else {
        return '';
      }
    }
  },
}
